package org.dlust.aop.softarch2lab1.Controller;

import org.dlust.aop.softarch2lab1.aspect.EnableRestCallLogs;
import org.dlust.aop.softarch2lab1.dto.InputRequestInfo;
import org.dlust.aop.softarch2lab1.dto.OutputResponseInfo;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class DemoRestController {

  @GetMapping("/testGet/{name}")
  @ResponseStatus(HttpStatus.OK)
  @EnableRestCallLogs
  public OutputResponseInfo testGetEndPoint(@PathVariable String name) {

    OutputResponseInfo result = new OutputResponseInfo();
    result.setResponse_state(HttpStatus.OK);
    Map<String, Object> hm = new HashMap<>();
    hm.put("Id", 1);
    hm.put("Input_Name", String.valueOf(name));
    result.setPayload(hm);
    return result;
  }


  @PostMapping("/testPost")
  @ResponseStatus(HttpStatus.CREATED)
  @EnableRestCallLogs
  public OutputResponseInfo testPostEndPoint(@RequestBody InputRequestInfo inputRequestInfo) {
    OutputResponseInfo result = new OutputResponseInfo();
    result.setResponse_state(HttpStatus.CREATED);
    Map<String, Object> hm = new HashMap<>();
    hm.put("Payload", inputRequestInfo);
    result.setPayload(hm);
    return result;
  }
}
